<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('入库作业')"/>
    <style>
        [v-cloak] {
            display: none;
        }
        .tag {
            display: inline-block;
            padding: 0 5px;
            line-height: 22px;
            color: #FFFFFF;
            border-radius: 3px;
        }
    </style>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li v-if="checkedSearch.indexOf('任务号') != -1">
                            任务号：<input type="text" id="taskNumber" name="taskNumber"/>
                        </li>
                        <li v-if="checkedSearch.indexOf('状态') != -1">
                            状态：
                            <select name="state">
                                <option value="">全部</option>
                                <option value="0">已下发</option>
                                <option value="1">执行中</option>
                                <option value="2">报错</option>
                                <option value="3">已完成</option>
                                <option value="8">取货货物不存在</option>
                                <option value="8">作废</option>
                                <option value="8">强制完成</option>
                                <option value="8">需盘点</option>
                                <option value="8">在途</option>
                            </select>
                        </li>
                        <li v-if="checkedSearch.indexOf('物料编码') != -1">
                            物料编码：<input type="text" id="materialProduct" name="materialProduct"/>
                        </li>
                        <li v-if="checkedSearch.indexOf('批次号') != -1">
                            批次号：<input type="text" id="batch" name="batch"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            <a class="btn btn-success btn-rounded btn-sm" @click="moreSearch()"><i class="fa fa-edit"></i>&nbsp;更多</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        <el-dialog title="搜索条件" width="200px" :visible.sync="showMore">
            <el-row>
                <el-col :span="24">
                    <el-checkbox style="margin-left: 28px" :indeterminate="isIndeterminate" v-model="checkAll" @change="handleCheckAllChange">全选</el-checkbox>
                    <el-checkbox-group v-model="checkedSearch" @change="handleCheckedSearchChange">
                        <el-checkbox style="display: block;margin-left: 28px" v-for="item in searches" :label="item" :key="item" v-cloak>{{item}}</el-checkbox>
                    </el-checkbox-group>
                </el-col>
            </el-row>
        </el-dialog>
        <div class="btn-group-sm" id="toolbar" role="group">
<!--            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="in:materialWork:export">-->
<!--                <i class="fa fa-download"></i> 导出全部-->
<!--            </a>-->
<!--            <a class="btn btn-info" @click="partExcel()" shiro:hasPermission="in:materialWork:partExcel">-->
<!--                <i class="fa fa-download"></i> 部分导出-->
<!--            </a>-->
            <a class="btn btn-primary" onclick="$.table.print()">
                <i class="fa fa-plus"></i> 打印
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true" style="white-space: nowrap"></table>
        </div>
    </div>
</div>

<div th:include="include :: footer"></div>
<script th:src="@{/wms/js/moreSearch.js}"></script>
<script th:inline="javascript">
    var prefix = ctx + "remove/taskInfo";

    const searchOptions = ['任务号', '状态', '物料编码', '批次号'];

    var app = new Vue({
        el: '.container-div',
        data: {
            showMore: false,
            checkAll: false,
            checkedSearch: ['任务号', '状态', '批次号'],
            searches: searchOptions,
            isIndeterminate: true
        },
        methods: {
            //部分导出
            partExcel(){
                var rows = $.common.isEmpty($.table._option.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns($.table._option.uniqueId);
                if(rows.length == 0){
                    $.modal.alertWarning("请至少选择一条记录");
                    return;
                }else{
                    $.modal.confirm("确认要导出选中的" + rows.length + "条数据吗?", function(){
                        var url = prefix + "/partExcel";
                        var data = {"ids": rows.join()};
                        $.post(url, data, function(result){
                            if(result.code == web_status.SUCCESS){
                                window.location.href = ctx + "common/download?fileName=" + encodeURI(result.msg) + "&delete=" + true;
                            }else if(result.code == web_status.WARNING){
                                $.modal.alertWarning(result.msg);
                            }else{
                                $.modal.alertError(result.msg);
                            }
                            $.modal.closeLoading();
                        });
                    });
                }
            }
        }
    })

    $(function() {
        var options = {
            url: prefix + "/moveTaskfindList",
            exportUrl: prefix + "/export",
            modalName: "入库作业",
            columns: [
                {
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '序号',
                    align: 'center',
                    visible: false
                },
                {
                    field: 'taskNumber',
                    title: '任务号',
                    align: 'center'
                },
                {
                    field: 'billNo',
                    title: '入库单号',
                    align: 'center'
                },
                {
                    field: 'createUserName',
                    title: '操作人名称',
                    align: 'center'
                },
                {
                    field: 'batch',
                    title: '批次',
                    align: 'center'
                },
                {
                    field: 'itemCode',
                    title: '物料编码',
                    align: 'center'
                },
                {
                    field: 'itemName',
                    title: '物料描述',
                    align: 'center'
                },
                {
                    field: 'sort',
                    title: '物料类型',
                    align: 'center',
                    formatter: function(value, row, index){
                        var actions = [];
                        if(value == 1){
                            actions.push("<span>钢材</span>");
                        }else if(value == 2){
                            actions.push("<span>铜材</span>");
                        }
                        return actions.join('');
                    }
                },
                {
                    field: 'startPosition',
                    title: '开始位置',
                    align: 'center'
                },
                {
                    field: 'endPosition',
                    title: '当前位置',
                    align: 'center'
                },
                {
                    field: 'memo',
                    title: '库位',
                    align: 'center'
                },
                {
                    field: 'state',
                    title: '状态',
                    align: 'center',
                    formatter: function(value, row, index){
                        var actions = [];
                        if(value == 1){
                            actions.push("<span class='tag' style='background-color: #999999'>已下发</span>");
                        }else if(value == 2){
                            actions.push("<span class='tag' style='background-color: #f8ac59'>执行中</span>");
                        }else if(value == 3){
                            actions.push("<span class='tag' style='background-color: #1ab394'>报错</span>");
                        }else if(value == 4){
                            actions.push("<span class='tag' style='background-color: #45ade1'>已完成</span>");
                        }else if(value == 5){
                            actions.push("<span class='tag' style='background-color: #999999'>取货货物不存在</span>");
                        }else if(value == 6){
                            actions.push("<span class='tag' style='background-color: #999999'>作废</span>");
                        }else if(value == 7){
                            actions.push("<span class='tag' style='background-color: #f8ac59'>强制完成</span>");
                        }else if(value == 8){
                            actions.push("<span class='tag' style='background-color: #f8ac59'>需盘点</span>");
                        }else if(value == 9){
                            actions.push("<span class='tag' style='background-color: #f8ac59'>在途</span>");
                        }
                        return actions.join('');
                    }
                },
                {
                    field: 'createUserName',
                    title: '创建人',
                    align: 'center'
                },
                {
                    field: 'taskStartTime',
                    title: '入库时间',
                    align: 'center',
                    formatter: function(value, row, index){
                        if (value == null) {
                            return '-';
                        } else {
                            return value.slice(0, 19);
                        }
                    }
                },
                {
                    field: 'taskEndTime',
                    title: '出库时间',
                    align: 'center',
                    formatter: function(value, row, index){
                        if (value == null) {
                            return '-';
                        } else {
                            return value.slice(0, 19);
                        }
                    }
                }
            ]
        };
        $.table.init(options);
    });
</script>
</body>
</html>
